import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";
import { getListApi as getAllCountryApi } from "@/api/configCenter/countryRegion";
import { reactive } from "vue";
import { getAllCompanyApi, getUserByPositionApi } from "@/api/managementCenter/departmentPersonnel";
import { getTreeChannelApi } from "@/api/configCenter/warehouseEntryChannel";
import { TreeSelect } from "ant-design-vue";
const SHOW_CHILD = TreeSelect.SHOW_CHILD;
export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNums",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "渠道",
    keyName: "channelIdList",
    optionsRequest: getTreeChannelApi,
    optReqParams: {},
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "label",
      value: "value",
      children: "children"
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  {
    type: "daterange",
    label: "拣货时间",
    keyName: "depositTime"
  },
  {
    type: "daterange",
    label: "下单时间",
    keyName: "createTime"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "国家",
    keyName: "countryRegionIdList",
    optionsRequest: getAllCountryApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "region",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "4", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),

  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "跟单员",
    keyName: "followIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "5", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "经营单位",
    keyName: "companyIdList",
    optionsRequest: getAllCompanyApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "datetimerange",
    label: "扣货时间",
    keyName: "detentionTime"
  },
  {
    type: "dict-select",
    label: "扣货原因",
    keyName: "releaseReasonList",
    lookupCode: "RELEASE_REASON",
    optConfig: {
      label: "name",
      value: "code"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }
];

export const tableColumnMap: Base.GeneraDataType<Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem>> = {
  1: [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "160"
    },
    {
      field: "detentionTime",
      title: "扣货时间",
      minWidth: "160",
      formatter: "formatDate"
    },
    {
      field: "releaseReason",
      title: "扣货原因",
      minWidth: "140",
      renderSlot: "releaseReason"
    },
    {
      field: "customerName",
      title: "客户",
      minWidth: "120"
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "90"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "warehouseCode",
      title: "仓库代码",
      minWidth: "100"
    },
    {
      field: "countryRegionName",
      title: "国家",
      minWidth: "90"
    },
    {
      field: "itemNumber",
      title: "件数",
      minWidth: "80"
    },
    {
      field: "actualWeight",
      title: "实重",
      minWidth: "80"
    },
    {
      field: "volumeWeight",
      title: "材积重",
      minWidth: "80"
    },
    {
      field: "squaresNumber",
      title: "体积",
      minWidth: "80"
    },
    {
      field: "settlementWeight",
      title: "收费重",
      minWidth: "90"
    },
    {
      field: "declaredValue",
      title: "申报价值",
      minWidth: "90"
    },

    {
      field: "bizName",
      title: "业务员",
      minWidth: "80"
    },
    {
      field: "followName",
      title: "跟单员",
      minWidth: "120"
    },
    {
      field: "internalRemark",
      title: "内部备注",
      minWidth: "120"
    },
    {
      field: "remark",
      title: "备注",
      minWidth: "120"
    },
    {
      field: "createTime",
      title: "下单时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "depositTime",
      title: "拣货时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "overdueBillNo",
      title: "逾期账单",
      minWidth: "140"
    },
    {
      field: "overdueAmount",
      title: "逾期金额",
      minWidth: "90"
    }
  ],
  2: [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "160"
    },
    {
      field: "detentionTime",
      title: "扣货时间",
      minWidth: "160",
      formatter: "formatDate"
    },
    {
      field: "releaseReason",
      title: "扣货原因",
      minWidth: "140",
      renderSlot: "releaseReason"
    },
    {
      field: "customerName",
      title: "客户",
      minWidth: "120"
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "90"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "warehouseCode",
      title: "仓库代码",
      minWidth: "100"
    },
    {
      field: "countryRegionName",
      title: "国家",
      minWidth: "90"
    },
    {
      field: "itemNumber",
      title: "件数",
      minWidth: "80"
    },
    {
      field: "actualWeight",
      title: "实重",
      minWidth: "80"
    },
    {
      field: "volumeWeight",
      title: "材积重",
      minWidth: "80"
    },
    {
      field: "squaresNumber",
      title: "体积",
      minWidth: "80"
    },
    {
      field: "settlementWeight",
      title: "收费重",
      minWidth: "90"
    },
    {
      field: "declaredValue",
      title: "申报价值",
      minWidth: "90"
    },

    {
      field: "bizName",
      title: "业务员",
      minWidth: "80"
    },
    {
      field: "followName",
      title: "跟单员",
      minWidth: "120"
    },
    {
      field: "internalRemark",
      title: "内部备注",
      minWidth: "120"
    },
    {
      field: "remark",
      title: "备注",
      minWidth: "120"
    },
    {
      field: "createTime",
      title: "下单时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "depositTime",
      title: "拣货时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "overdueBillNo",
      title: "逾期账单",
      minWidth: "140"
    },
    {
      field: "overdueAmount",
      title: "逾期金额",
      minWidth: "90"
    }
  ],
  3: [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "160"
    },
    {
      field: "detentionTime",
      title: "扣货时间",
      minWidth: "160",
      formatter: "formatDate"
    },
    {
      field: "releaseReason",
      title: "扣货原因",
      minWidth: "140",
      renderSlot: "releaseReason"
    },
    {
      field: "customerName",
      title: "客户",
      minWidth: "120"
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "90"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "warehouseCode",
      title: "仓库代码",
      minWidth: "100"
    },
    {
      field: "countryRegionName",
      title: "国家",
      minWidth: "90"
    },
    {
      field: "itemNumber",
      title: "件数",
      minWidth: "80"
    },
    {
      field: "actualWeight",
      title: "实重",
      minWidth: "80"
    },
    {
      field: "volumeWeight",
      title: "材积重",
      minWidth: "80"
    },
    {
      field: "squaresNumber",
      title: "体积",
      minWidth: "80"
    },
    {
      field: "settlementWeight",
      title: "收费重",
      minWidth: "90"
    },
    {
      field: "declaredValue",
      title: "申报价值",
      minWidth: "90"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "80"
    },
    {
      field: "followName",
      title: "跟单员",
      minWidth: "120"
    },
    {
      field: "internalRemark",
      title: "内部备注",
      minWidth: "120"
    },
    {
      field: "remark",
      title: "备注",
      minWidth: "120"
    },
    {
      field: "createTime",
      title: "下单时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "depositTime",
      title: "拣货时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "overdueBillNo",
      title: "逾期账单",
      minWidth: "140"
    },
    {
      field: "overdueAmount",
      title: "逾期金额",
      minWidth: "90"
    },
    {
      field: "releaseApplyResult",
      title: "驳回原因",
      minWidth: "120"
    },
    {
      field: "agentStatus",
      title: "代理状态标记",
      minWidth: "120",
      formatter: ({ cellValue }: any) => {
        if (cellValue === 1) return "待通知";
        else if (cellValue === 2) return "已拦截";
        else return "已出货";
      }
    }
  ],
  4: [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "160"
    },
    {
      field: "detentionTime",
      title: "扣货时间",
      minWidth: "160",
      formatter: "formatDate"
    },
    {
      field: "releaseReason",
      title: "扣货原因",
      minWidth: "140",
      renderSlot: "releaseReason"
    },
    {
      field: "customerName",
      title: "客户",
      minWidth: "120"
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "90"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "warehouseCode",
      title: "仓库代码",
      minWidth: "100"
    },
    {
      field: "countryRegionName",
      title: "国家",
      minWidth: "90"
    },
    {
      field: "itemNumber",
      title: "件数",
      minWidth: "80"
    },
    {
      field: "actualWeight",
      title: "实重",
      minWidth: "80"
    },
    {
      field: "volumeWeight",
      title: "材积重",
      minWidth: "80"
    },
    {
      field: "squaresNumber",
      title: "体积",
      minWidth: "80"
    },
    {
      field: "settlementWeight",
      title: "收费重",
      minWidth: "90"
    },
    {
      field: "declaredValue",
      title: "申报价值",
      minWidth: "90"
    },

    {
      field: "bizName",
      title: "业务员",
      minWidth: "80"
    },
    {
      field: "followName",
      title: "跟单员",
      minWidth: "120"
    },
    {
      field: "internalRemark",
      title: "内部备注",
      minWidth: "120"
    },
    {
      field: "remark",
      title: "备注",
      minWidth: "120"
    },
    {
      field: "createTime",
      title: "下单时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "depositTime",
      title: "拣货时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "overdueBillNo",
      title: "逾期账单",
      minWidth: "140"
    },
    {
      field: "overdueAmount",
      title: "逾期金额",
      minWidth: "90"
    }
  ],
  "-1": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "160"
    },
    {
      field: "detentionTime",
      title: "扣货时间",
      minWidth: "160",
      formatter: "formatDate"
    },
    {
      field: "releaseReason",
      title: "扣货原因",
      minWidth: "140",
      renderSlot: "releaseReason"
    },
    {
      field: "customerName",
      title: "客户",
      minWidth: "120"
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "90"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "warehouseCode",
      title: "仓库代码",
      minWidth: "100"
    },
    {
      field: "countryRegionName",
      title: "国家",
      minWidth: "90"
    },
    {
      field: "itemNumber",
      title: "件数",
      minWidth: "80"
    },
    {
      field: "actualWeight",
      title: "实重",
      minWidth: "80"
    },
    {
      field: "volumeWeight",
      title: "材积重",
      minWidth: "80"
    },
    {
      field: "squaresNumber",
      title: "体积",
      minWidth: "80"
    },
    {
      field: "settlementWeight",
      title: "收费重",
      minWidth: "90"
    },
    {
      field: "declaredValue",
      title: "申报价值",
      minWidth: "90"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "80"
    },
    {
      field: "followName",
      title: "跟单员",
      minWidth: "120"
    },
    {
      field: "internalRemark",
      title: "内部备注",
      minWidth: "120"
    },
    {
      field: "remark",
      title: "备注",
      minWidth: "120"
    },
    {
      field: "createTime",
      title: "下单时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "depositTime",
      title: "拣货时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "overdueBillNo",
      title: "逾期账单",
      minWidth: "140"
    },
    {
      field: "overdueAmount",
      title: "逾期金额",
      minWidth: "90"
    },
    {
      field: "releaseStatus",
      title: "状态",
      minWidth: "120",
      renderSlot: "releaseStatus",
      fixed: "right"
    }
  ]
};
